
package tsp;

import java.util.ArrayList;

public class TSP_Solution {
    private ArrayList<Integer> cycle;

    public int[] getAffectation() {
        return affectation;
    }

    public void setAffectation(int[] affectation) {
        this.affectation = affectation;
    }

    public ArrayList<Integer> getCycle() {
        return cycle;
    }

    public void setCycle(ArrayList<Integer> cycle) {
        this.cycle = cycle;
    }
    private int[] affectation; /* indice : pour un sommet donné hors cycle,
    valeur : le sommet auquel il est rataché */

    private double lambda;
    private int alpha;
    private int coutSolution;

    public TSP_Solution() {
        coutSolution = Integer.MAX_VALUE;
    }

    public TSP_Solution(ArrayList<Integer> cycle, int[] affectation, int coutSolution) {
        this.cycle = cycle;
        this.affectation = affectation;
        this.lambda = 0.0;
        this.alpha = 0;
        this.coutSolution = coutSolution;
    }
    
    public TSP_Solution(ArrayList<Integer> cycle, int[] affectation, double lambda, int alpha, int coutSolution) {
        this.cycle = cycle;
        this.affectation = affectation;
        this.lambda = lambda;
        this.alpha = alpha;
        this.coutSolution = coutSolution;
    }

    public int getCoutSolution() {
        return coutSolution;
    }

    public double getLambda() {
        return lambda;
    }

    

     /**********************************************************
     * ******* FONCTIONS D'AFFICHAGE **************************
     *********************************************************/

    /**
     * Affiche le cycle de la solution
     */
    public void afficherCycle() {
        String str = "\n=== CYCLE DE LA SOLUTION "
                + "(" + cycle.size() + " sommets) ===\n";

        str += cycle.toString();

        System.out.println(str);
    }

    /**
     * Affiche les affectations au cycle
     */
    public void afficherAffectations() {
        String str = "\n=== AFFECTATIONS ===\n";

        for (int i = 0; i < affectation.length; i++) {
            if (!cycle.contains(i)) {
                str += "(" + i + "=>" + affectation[i] + ") ";
            }
        }
        str += "\n";

        System.out.println(str);
    }

    /**
     * Affiche le cout de la solution (cycle + affectations) finale
     */
    public void afficherCoutSolution() {
        String str = "\n=== COUT SOLUTION ===\n";

        str += coutSolution;

        System.out.println(str);
    }

    @Override
    public String toString() {
        return "("+ cycle.size() +" , "+ coutSolution +")";
    }
}
